<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="Cask Data, Inc." name="author" />
<meta content="Copyright © 2014-2017 Cask Data, Inc." name="copyright" />


    <meta name="git_release" content="6.1.1">
    <meta name="git_hash" content="05fbac36f9f7aadeb44f5728cea35136dbc243e5">
    <meta name="git_timestamp" content="2020-02-09 08:22:47 +0800">
    <title>Tables</title>

    <link rel="stylesheet" href="../../_static/cdap-bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/bootstrap-3.3.6/css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/bootstrap-3.3.6/css/bootstrap-theme.min.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/bootstrap-sphinx.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/cdap-dynamicscrollspy-4.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/jquery.mCustomScrollbar.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/cdap-jquery.mCustomScrollbar.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/css/abixTreeList-2.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/cdap-bootstrap.css" type="text/css" />

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '6.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>

    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="top" title="Cask Data Application Platform 6.1.1 Documentation" href="../../index.html" />
    <link rel="up" title="Datasets" href="index.html" />
    <link rel="next" title="FileSet Dataset" href="fileset.html" />
    <link rel="prev" title="Datasets Overview" href="overview.html" />
    <!-- block extrahead -->
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <!-- block extrahead end -->

</head>
<body role="document">

<!-- block navbar -->
<div id="navbar" class="navbar navbar-inverse navbar-default navbar-fixed-top">
    <div class="container-fluid">
      <div class="row">
        <div class="navbar-header">
          <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
          <a class="navbar-brand" href="../../table-of-contents/../../index.html">
            <span><img alt="CDAP logo" src="../../_static/cdap_logo.svg"/></span>
          </a>

          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>

          <div class="pull-right">
            <div class="dropdown version-dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown"
                role="button" aria-haspopup="true" aria-expanded="false">
                v 6.1.1 <span class="caret"></span>
              </a>
              <ul class="dropdown-menu">
                <li><a href="//docs.cdap.io/cdap/5.1.2/en/index.html">v 5.1.2</a></li>
                <li><a href="//docs.cdap.io/cdap/4.3.4/en/index.html">v 4.3.4</a></li>
              </ul>
            </div>
          </div>
          <form class="navbar-form navbar-right navbar-search" action="../../search.html" method="get">
            <div class="form-group">
              <div class="navbar-search-image material-icons"></div>
              <input type="text" name="q" class="form-control" placeholder="  Search" />
            </div>
            <input type="hidden" name="check_keywords" value="yes" />
            <input type="hidden" name="area" value="default" />
          </form>

          <div class="collapse navbar-collapse nav-collapse navbar-right navbar-navigation">
            <ul class="nav navbar-nav"><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="../../table-of-contents/../../index.html">简介</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link current" href="../../table-of-contents/../../guides.html">手册</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="../../table-of-contents/../../reference-manual/index.html">参考</a></li><li class="docsite-nav-tab-container"><a class="docsite-nav-tab-link " href="../../table-of-contents/../../faqs/index.html">帮助</a></li>
            </ul>
          </div>

        </div>
      </div>
    </div>
  </div><!-- block navbar end -->
<!-- block main content -->
<div class="main-container container">
  <div class="row"><div class="col-md-2">
      <div id="sidebar" class="bs-sidenav scrollable-y-outside" role="complementary">
<!-- theme_manual: developer-manual -->
<!-- theme_manual_highlight: guides -->
<!-- sidebar_title_link: ../../table-of-contents/../../guides.html -->

  <div role="note" aria-label="manuals links"><h3><a href="../../table-of-contents/../../guides.html">Guides</a></h3>

    <ul class="this-page-menu">
      <li class="toctree-l1"><a href="../../table-of-contents/../../user-guide/index.html" rel="nofollow">用户手册</a>
      </li>
      <li class="toctree-l1"><b><a href="../../table-of-contents/../../developer-manual/index.html" rel="nofollow">开发手册</a></b>
      <nav class="pagenav">
      <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../index.html"> 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started/index.html"> 入门指南</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/sandbox/index.html">CDAP Sandbox</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/zip.html">二进制 Zip 文件</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/zip.html#cdap-sandbox">启动和停止 CDAP Sandbox</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/virtual-machine.html">虚拟机镜像</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getting-started/sandbox/docker.html">Docker 镜像</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/quick-start.html">快速入门</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/dev-env.html">搭建开发环境</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/start-stop-cdap.html">启动和停止 CDAP</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../getting-started/building-apps.html">构建并运行应用</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../overview/index.html"> 概述</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../overview/anatomy.html"> 大数据应用剖析</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../overview/modes.html"> 模式和组件</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../overview/abstractions.html"> 核心概念</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../overview/interfaces.html"> 编程接口</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html"> 抽象概念</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../core.html"> Core Abstractions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../applications.html"> Applications</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html"> Datasets</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="overview.html"> Overview</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#"> Table API</a></li>
<li class="toctree-l3"><a class="reference internal" href="fileset.html"> FileSets</a></li>
<li class="toctree-l3"><a class="reference internal" href="partitioned-fileset.html"> Partitioned FileSets</a></li>
<li class="toctree-l3"><a class="reference internal" href="time-partitioned-fileset.html"> TimePartitioned FileSets</a></li>
<li class="toctree-l3"><a class="reference internal" href="system-custom.html"> System and Custom Datasets</a></li>
<li class="toctree-l3"><a class="reference internal" href="permissions.html"> Dataset Permissions</a></li>
<li class="toctree-l3"><a class="reference internal" href="cube.html"> Cube Dataset</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mapreduce-programs.html"> MapReduce Programs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../plugins.html"> Plugins</a></li>
<li class="toctree-l2"><a class="reference internal" href="../schedules.html"> Schedules</a></li>
<li class="toctree-l2"><a class="reference internal" href="../secure-keys.html"> Secure Keys</a></li>
<li class="toctree-l2"><a class="reference internal" href="../services.html"> Services</a></li>
<li class="toctree-l2"><a class="reference internal" href="../spark-programs.html"> Spark Programs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../workers.html"> Workers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../workflows.html"> Workflows</a></li>
<li class="toctree-l2"><a class="reference internal" href="../artifacts.html"> Artifacts</a></li>
<li class="toctree-l2"><a class="reference internal" href="../program-lifecycle.html"> Program Lifecycle</a></li>
<li class="toctree-l2"><a class="reference internal" href="../namespaces.html"> Namespaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../transaction-system.html"> Transaction System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../transactional-messaging-system.html"> Transactional Messaging System</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../metadata/index.html"> 元数据</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/system-metadata.html"> System Metadata</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/discovery-lineage.html"> Discovery and Lineage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/field-lineage.html"> Field Level Lineage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/audit-logging.html"> Audit Logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/metadata-ui.html"> CDAP Metadata UI</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../metadata/programmatic-metadata.html"> Accessing metadata programmatically</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../pipelines/index.html"> 数据流管道</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/concepts-design.html"> Concepts and Design</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/getting-started.html"> Getting Started</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/studio.html"> CDAP Studio</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/creating-pipelines.html"> Creating Pipelines</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/running-pipelines.html"> Running Pipelines</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/plugin-management.html"> Plugin Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/plugins/index.html"> Plugin Reference</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/actions/index.html"> Action Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/sources/index.html"> Source Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/transforms/index.html"> Transform Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/analytics/index.html"> Analytic Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/sinks/index.html"> Sink Plugins</a><ul class="simple">
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/shared-plugins/index.html"> Shared Plugins</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../../pipelines/plugins/shared-plugins/core.html">CoreValidator</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/plugins/post-run-plugins/index.html"> Post-run Plugins</a><ul class="simple">
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/developing-pipelines.html"> Developing Pipelines</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/developing-plugins/index.html"> Developing Plugins</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/plugin-basics.html">Plugin Basics</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/creating-a-plugin.html">Creating a Plugin</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/presentation-plugins.html">Plugin Presentation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/testing-plugins.html">Testing Plugins</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../pipelines/developing-plugins/packaging-plugins.html">Packaging Plugins</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../pipelines/how-cdap-pipelines-work.html"> How CDAP Pipelines Work</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../cloud-runtimes/index.html"> 云平台运行</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/concepts/index.html"> Concepts</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/provisioners/index.html"> Provisioners</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/provisioners/gcp-dataproc.html">Google Dataproc</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/provisioners/aws-emr.html">Amazon Elastic MapReduce</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/provisioners/remote-hadoop.html">Remote Hadoop</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/profiles/index.html"> Profiles</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/profiles/creating-profiles.html">Creating Profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/profiles/assigning-profiles.html">Assigning Profiles</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cloud-runtimes/profiles/admin-controls.html">Admin Controls</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../cloud-runtimes/example/index.html"> Example</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../security/index.html"> 安全</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../security/client-authentication.html">Client Authentication</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/cdap-authentication-clients-java.html">CDAP Authentication Client for Java</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/cdap-authentication-clients-python.html">CDAP Authentication Client for Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/custom-authentication.html">Custom Authentication</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../security/authorization-extensions.html">Authorization Extensions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../testing/index.html"> 测试和调试</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../testing/testing.html"> Testing a CDAP Application</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../testing/debugging.html"> Debugging</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../testing/troubleshooting.html"> Troubleshooting</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../ingesting-tools/index.html"> 数据融合</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-stream-clients-java.html">CDAP Stream Client for Java</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-stream-clients-python.html">CDAP Stream Client for Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-stream-clients-ruby.html">CDAP Stream Client for Ruby</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../ingesting-tools/cdap-flume.html">CDAP Flume</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../data-exploration/index.html"> 数据探索</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/filesets.html"> Fileset Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/tables.html"> Table Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/object-mapped-tables.html"> ObjectMappedTable Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/custom-datasets.html"> Custom Dataset Exploration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../data-exploration/hive-execution-engines.html"> Hive Execution Engines</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../advanced/index.html"> 高级主题</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/application-logback.html"> Application Logback</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/best-practices.html"> Best Practices</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/class-loading.html"> Class Loading</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/configuring-resources.html"> Configuring Program Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../advanced/program-retry-policies.html"> Program Retry Policies</a></li>
</ul>
</li>
</ul>
</nav>
      </li>
      <li class="toctree-l1"><a href="../../table-of-contents/../../admin-manual/index.html" rel="nofollow">管理手册</a>
      </li>
      <li class="toctree-l1"><a href="../../table-of-contents/../../integrations/index.html" rel="nofollow">集成手册</a>
      </li>
      <li class="toctree-l1"><a href="../../table-of-contents/../../examples-manual/index.html" rel="nofollow">最佳实践</a>
      </li>
    </ul>
  </div></div>
    </div><div class="col-md-8 content" id="main-content">
    
  <div class="section" id="tables">
<h1>Tables<a class="headerlink" href="#tables" title="Permalink to this headline">🔗</a></h1>
<p>The <code class="docutils literal notranslate"><span class="pre">Table</span></code> API provides basic methods to perform read, write and delete operations,
plus special scan, atomic increment and compare-and-swap operations:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Read</span>
<span class="kd">public</span> <span class="n">Row</span> <span class="nf">get</span><span class="p">(</span><span class="n">Get</span> <span class="n">get</span><span class="p">)</span>
<span class="kd">public</span> <span class="n">Row</span> <span class="nf">get</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">byte</span><span class="o">[]</span> <span class="nf">get</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">column</span><span class="p">)</span>
<span class="kd">public</span> <span class="n">Row</span> <span class="nf">get</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[][]</span> <span class="n">columns</span><span class="p">)</span>
<span class="kd">public</span> <span class="n">Row</span> <span class="nf">get</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">startColumn</span><span class="p">,</span>
               <span class="kt">byte</span><span class="o">[]</span> <span class="n">stopColumn</span><span class="p">,</span> <span class="kt">int</span> <span class="n">limit</span><span class="p">)</span>

<span class="c1">// Scan</span>
<span class="kd">public</span> <span class="n">Scanner</span> <span class="nf">scan</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">startRow</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">stopRow</span><span class="p">)</span>

<span class="c1">// Write</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">put</span><span class="p">(</span><span class="n">Put</span> <span class="n">put</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">put</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">column</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">value</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">put</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[][]</span> <span class="n">columns</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[][]</span> <span class="n">values</span><span class="p">)</span>

<span class="c1">// Compare And Swap</span>
<span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">compareAndSwap</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">column</span><span class="p">,</span>
                              <span class="kt">byte</span><span class="o">[]</span> <span class="n">expectedValue</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">newValue</span><span class="p">)</span>

<span class="c1">// Increment and return result</span>
<span class="kd">public</span> <span class="n">Row</span> <span class="nf">incrementAndGet</span><span class="p">(</span><span class="n">Increment</span> <span class="n">increment</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">long</span> <span class="nf">incrementAndGet</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">column</span><span class="p">,</span> <span class="kt">long</span> <span class="n">amount</span><span class="p">)</span>
<span class="kd">public</span> <span class="n">Row</span> <span class="nf">incrementAndGet</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[][]</span> <span class="n">columns</span><span class="p">,</span> <span class="kt">long</span><span class="o">[]</span> <span class="n">amounts</span><span class="p">)</span>

<span class="c1">// Increment without result</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">increment</span><span class="p">(</span><span class="n">Increment</span> <span class="n">increment</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">increment</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">column</span><span class="p">,</span> <span class="kt">long</span> <span class="n">amount</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">increment</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[][]</span> <span class="n">columns</span><span class="p">,</span> <span class="kt">long</span><span class="o">[]</span> <span class="n">amounts</span><span class="p">)</span>

<span class="c1">// Delete</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">delete</span><span class="p">(</span><span class="n">Delete</span> <span class="n">delete</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">delete</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">delete</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">column</span><span class="p">)</span>
<span class="kd">public</span> <span class="kt">void</span> <span class="nf">delete</span><span class="p">(</span><span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[][]</span> <span class="n">columns</span><span class="p">)</span>
</pre></div>
</div>
<p>Each basic operation has a method that takes an operation-type object as a parameter
plus handy methods for working directly with byte arrays.
If your application code already deals with byte arrays, you can use the latter methods to save a conversion.</p>
<div class="section" id="read">
<h2>Read<a class="headerlink" href="#read" title="Permalink to this headline">🔗</a></h2>
<p>A <code class="docutils literal notranslate"><span class="pre">get</span></code> operation reads all columns or a selection of columns of a single row:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Table</span> <span class="n">t</span><span class="p">;</span>
<span class="kt">byte</span><span class="o">[]</span> <span class="n">rowKey1</span><span class="p">;</span>
<span class="kt">byte</span><span class="o">[]</span> <span class="n">columnX</span><span class="p">;</span>
<span class="kt">byte</span><span class="o">[]</span> <span class="n">columnY</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">n</span><span class="p">;</span>

<span class="c1">// Read all columns of a row</span>
<span class="n">Row</span> <span class="n">row</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="k">new</span> <span class="n">Get</span><span class="p">(</span><span class="s">&quot;rowKey1&quot;</span><span class="p">));</span>

<span class="c1">// Read specified columns from a row</span>
<span class="n">Row</span> <span class="n">rowSelection</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="k">new</span> <span class="n">Get</span><span class="p">(</span><span class="s">&quot;rowKey1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column2&quot;</span><span class="p">));</span>

<span class="c1">// Reads a column range from x (inclusive) to y (exclusive)</span>
<span class="c1">// with a limit of n return values</span>
<span class="n">rowSelection</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">rowKey1</span><span class="p">,</span> <span class="n">columnX</span><span class="p">,</span> <span class="n">columnY</span><span class="p">;</span> <span class="n">n</span><span class="p">);</span>

<span class="c1">// Read only one column in one row byte[]</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">rowKey1</span><span class="p">,</span> <span class="n">columnX</span><span class="p">);</span>
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">Row</span></code> object provides access to the row data including its columns. If only a
selection of row columns is requested, the returned <code class="docutils literal notranslate"><span class="pre">Row</span></code> object will contain only these columns.
The <code class="docutils literal notranslate"><span class="pre">Row</span></code> object provides an extensive API for accessing returned column values:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Get column value as a byte array</span>
<span class="kt">byte</span><span class="o">[]</span> <span class="n">value</span> <span class="o">=</span> <span class="n">row</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">);</span>

<span class="c1">// Get column value of a specific type</span>
<span class="n">String</span> <span class="n">valueAsString</span> <span class="o">=</span> <span class="n">row</span><span class="p">.</span><span class="na">getString</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">);</span>
<span class="n">Integer</span> <span class="n">valueAsInteger</span> <span class="o">=</span> <span class="n">row</span><span class="p">.</span><span class="na">getInt</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>When requested, the value of a column is converted to a specific type automatically.
If the column is absent in a row, the returned value is <code class="docutils literal notranslate"><span class="pre">null</span></code>. To return primitive types,
the corresponding methods accept a default value to be returned when the column is absent:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Get column value as a primitive type or 0 if column is absent</span>
<span class="kt">long</span> <span class="n">valueAsLong</span> <span class="o">=</span> <span class="n">row</span><span class="p">.</span><span class="na">getLong</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span>
</pre></div>
</div>
<p>Multiple rows can be requested together using a variation of the <code class="docutils literal notranslate"><span class="pre">get</span></code> operation that takes a
list of <code class="docutils literal notranslate"><span class="pre">Get</span></code> objects to be retrieved:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">Table</span> <span class="n">t</span><span class="p">;</span>

<span class="c1">// Define the rows to retrieve</span>
<span class="n">List</span><span class="o">&lt;</span><span class="n">Get</span><span class="o">&gt;</span> <span class="n">gets</span> <span class="o">=</span> <span class="n">Lists</span><span class="p">.</span><span class="na">newArrayList</span><span class="p">();</span>
<span class="n">gets</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">Get</span><span class="p">(</span><span class="s">&quot;row1&quot;</span><span class="p">));</span>
<span class="c1">// Separate columns can be requested for each row</span>
<span class="n">gets</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">Get</span><span class="p">(</span><span class="s">&quot;row2&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column2&quot;</span><span class="p">));</span>
<span class="n">gets</span><span class="p">.</span><span class="na">add</span><span class="p">(</span><span class="k">new</span> <span class="n">Get</span><span class="p">(</span><span class="s">&quot;row3&quot;</span><span class="p">));</span>

<span class="n">List</span><span class="o">&lt;</span><span class="n">Row</span><span class="o">&gt;</span> <span class="n">rows</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">get</span><span class="p">(</span><span class="n">gets</span><span class="p">);</span>
</pre></div>
</div>
<p>Each <code class="docutils literal notranslate"><span class="pre">Row</span></code> object in the returned list will contain the results for one of the requested row
keys.  When multiple rows must be retrieved together, this version of the <code class="docutils literal notranslate"><span class="pre">get</span></code> operation
allows the storage provider to perform more efficient batching of the operations, if supported.</p>
</div>
<div class="section" id="scan">
<h2>Scan<a class="headerlink" href="#scan" title="Permalink to this headline">🔗</a></h2>
<p>A <code class="docutils literal notranslate"><span class="pre">scan</span></code> operation fetches a subset of rows or all of the rows of a Table:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kt">byte</span><span class="o">[]</span> <span class="n">startRow</span><span class="p">;</span>
<span class="kt">byte</span><span class="o">[]</span> <span class="n">stopRow</span><span class="p">;</span>
<span class="n">Row</span> <span class="n">row</span><span class="p">;</span>

<span class="c1">// Scan all rows from startRow (inclusive) to</span>
<span class="c1">// stopRow (exclusive)</span>
<span class="k">try</span> <span class="p">(</span><span class="n">Scanner</span> <span class="n">scanner</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">scan</span><span class="p">(</span><span class="n">startRow</span><span class="p">,</span> <span class="n">stopRow</span><span class="p">))</span> <span class="p">{</span>
  <span class="k">while</span> <span class="p">((</span><span class="n">row</span> <span class="o">=</span> <span class="n">scanner</span><span class="p">.</span><span class="na">next</span><span class="p">())</span> <span class="o">!=</span> <span class="kc">null</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">LOG</span><span class="p">.</span><span class="na">info</span><span class="p">(</span><span class="s">&quot;column1: &quot;</span> <span class="o">+</span> <span class="n">row</span><span class="p">.</span><span class="na">getString</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">,</span> <span class="s">&quot;null&quot;</span><span class="p">));</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>To scan a set of rows not bounded by <code class="docutils literal notranslate"><span class="pre">startRow</span></code> and/or <code class="docutils literal notranslate"><span class="pre">stopRow</span></code>
you can pass <code class="docutils literal notranslate"><span class="pre">null</span></code> as their value:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kt">byte</span><span class="o">[]</span> <span class="n">startRow</span><span class="p">;</span>
<span class="c1">// Scan all rows of a table</span>
<span class="n">Scanner</span> <span class="n">allRows</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">scan</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
<span class="c1">// Scan all columns up to stopRow (exclusive)</span>
<span class="n">Scanner</span> <span class="n">headRows</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">scan</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="n">stopRow</span><span class="p">);</span>
<span class="c1">// Scan all columns starting from startRow (inclusive)</span>
<span class="n">Scanner</span> <span class="n">tailRows</span> <span class="o">=</span> <span class="n">t</span><span class="p">.</span><span class="na">scan</span><span class="p">(</span><span class="n">startRow</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="write">
<h2>Write<a class="headerlink" href="#write" title="Permalink to this headline">🔗</a></h2>
<p>A <code class="docutils literal notranslate"><span class="pre">put</span></code> operation writes data into a row:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Write a set of columns with their values</span>
<span class="n">t</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="k">new</span> <span class="n">Put</span><span class="p">(</span><span class="s">&quot;rowKey1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">,</span> <span class="s">&quot;value1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column2&quot;</span><span class="p">,</span> <span class="mi">55L</span><span class="p">));</span>
</pre></div>
</div>
<p>Note that the column value cannot be empty, that is, it must have at least length one.</p>
</div>
<div class="section" id="compare-and-swap">
<h2>Compare and Swap<a class="headerlink" href="#compare-and-swap" title="Permalink to this headline">🔗</a></h2>
<p>A swap operation compares the existing value of a column with an expected value,
and if it matches, replaces it with a new value.
The operation returns <code class="docutils literal notranslate"><span class="pre">true</span></code> if it succeeds and <code class="docutils literal notranslate"><span class="pre">false</span></code> otherwise:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kt">byte</span><span class="o">[]</span> <span class="n">expectedCurrentValue</span><span class="p">;</span>
<span class="kt">byte</span><span class="o">[]</span> <span class="n">newValue</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">t</span><span class="p">.</span><span class="na">compareAndSwap</span><span class="p">(</span><span class="n">rowKey1</span><span class="p">,</span> <span class="n">columnX</span><span class="p">,</span>
      <span class="n">expectedCurrentValue</span><span class="p">,</span> <span class="n">newValue</span><span class="p">))</span> <span class="p">{</span>
  <span class="n">LOG</span><span class="p">.</span><span class="na">info</span><span class="p">(</span><span class="s">&quot;Current value was different from expected&quot;</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Note that the column value cannot be empty, that is, it must have at least length one.</p>
</div>
<div class="section" id="increment">
<h2>Increment<a class="headerlink" href="#increment" title="Permalink to this headline">🔗</a></h2>
<p>An increment operation increments a <code class="docutils literal notranslate"><span class="pre">long</span></code> value of one or more columns by either <code class="docutils literal notranslate"><span class="pre">1L</span></code>
or an integer amount <em>n</em>.  If a column does not exist, it is created with an assumed value of zero
before the increment is applied:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Write long value to a column of a row</span>
<span class="n">t</span><span class="p">.</span><span class="na">put</span><span class="p">(</span><span class="k">new</span> <span class="n">Put</span><span class="p">(</span><span class="s">&quot;rowKey1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">,</span> <span class="mi">55L</span><span class="p">));</span>
<span class="c1">// Increment values of several columns in a row</span>
<span class="n">t</span><span class="p">.</span><span class="na">increment</span><span class="p">(</span><span class="k">new</span> <span class="n">Increment</span><span class="p">(</span><span class="s">&quot;rowKey1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">,</span> <span class="mi">1L</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column2&quot;</span><span class="p">,</span> <span class="mi">23L</span><span class="p">));</span>
</pre></div>
</div>
<p>If the existing value of the column cannot be converted to a <code class="docutils literal notranslate"><span class="pre">long</span></code>,
a <code class="docutils literal notranslate"><span class="pre">NumberFormatException</span></code> will be thrown.</p>
<p>Two types of increment operations are supported:</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">incrementAndGet(...)</span></code> operations will increment the currently stored value and return the
result; and</li>
<li><code class="docutils literal notranslate"><span class="pre">increment(...)</span></code> operations will increment the currently stored value without any return
value.</li>
</ul>
<div class="section" id="read-less-increments">
<h3>Read-less Increments<a class="headerlink" href="#read-less-increments" title="Permalink to this headline">🔗</a></h3>
<p>By default, an increment operation will need to first perform a read operation to find the
currently stored column value, apply the increment to the stored value, and then write the final
result.  For high write volume workloads, with only occassional reads, this can impose a great
deal of unnecessary overhead for increments.</p>
<p>In these situations, you can configure the dataset to support read-less increments.  With read-less
increments, each operation only performs a write operation, storing the incremental value for the
column in a new cell.  This completely eliminates the cost of the read operation when performing
increments.  Instead, when reading the value for a column storing data for read-less increments,
all of the stored increment values are read and summed up together with the last stored complete
sum, in order to compute the final result.  As a result, read operations become more expensive, but
this trade-off can be very beneficial for workloads dominated by writes.</p>
<p>Read-less increments can only be used with the <code class="docutils literal notranslate"><span class="pre">increment(...)</span></code> operation, since it does not
return a value.  To configure a dataset to support read-less increments:</p>
<ol class="arabic simple">
<li>Set the property <code class="docutils literal notranslate"><span class="pre">dataset.table.readless.increment</span></code> to <code class="docutils literal notranslate"><span class="pre">true</span></code> in the Dataset properties.</li>
<li>Use the <code class="docutils literal notranslate"><span class="pre">increment(...)</span></code> methods for any operations that do not need the result value of the
increment operation.</li>
</ol>
<p><em>Note:</em> the current implementation of read-less increments uses an HBase coprocessor to prefix the
stored values for incremental updates with a special prefix.  Since this prefix could occur
naturally in other stored data values, it is highly recommended that increments be stored in a
separate dataset and not be mixed in with other types of values.  This will ensure that other data is
not mis-identified as a stored increment and prevent incorrect results.</p>
</div>
</div>
<div class="section" id="delete">
<h2>Delete<a class="headerlink" href="#delete" title="Permalink to this headline">🔗</a></h2>
<p>A delete operation removes an entire row or a subset of its columns:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="c1">// Delete the entire row</span>
<span class="n">t</span><span class="p">.</span><span class="na">delete</span><span class="p">(</span><span class="k">new</span> <span class="n">Delete</span><span class="p">(</span><span class="s">&quot;rowKey1&quot;</span><span class="p">));</span>
<span class="c1">// Delete a selection of columns from the row</span>
<span class="n">t</span><span class="p">.</span><span class="na">delete</span><span class="p">(</span><span class="k">new</span> <span class="n">Delete</span><span class="p">(</span><span class="s">&quot;rowKey1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column1&quot;</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;column2&quot;</span><span class="p">));</span>
</pre></div>
</div>
<p>Note that specifying a set of columns helps to perform delete operation faster.
When you want to delete all the columns of a row and you know all of them,
passing all of them will make the deletion faster. Deleting all the columns of a row will
also delete the entire row, as the underlying implementation of a Table is a
<a class="reference external" href="http://en.wikipedia.org/wiki/Column-oriented_DBMS">columnar store.</a></p>
</div>
<div class="section" id="writing-from-mapreduce">
<h2>Writing from MapReduce<a class="headerlink" href="#writing-from-mapreduce" title="Permalink to this headline">🔗</a></h2>
<p>Table implements the <code class="docutils literal notranslate"><span class="pre">BatchWritable</span></code> interface, using <code class="docutils literal notranslate"><span class="pre">byte[]</span></code> as the key and
<code class="docutils literal notranslate"><span class="pre">Put</span></code> as the value for each write. To write to a table from MapReduce, use these
types as the output types of your Reducer (or Mapper in case of a map-only program).
For example, the Reducer can be defined as follows:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="cm">/**</span>
<span class="cm"> * A reducer that sums up the counts for each key.</span>
<span class="cm"> */</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kd">class</span> <span class="nc">Counter</span> <span class="kd">extends</span> <span class="n">Reducer</span><span class="o">&lt;</span><span class="n">Text</span><span class="p">,</span> <span class="n">IntWritable</span><span class="p">,</span> <span class="kt">byte</span><span class="o">[]</span><span class="p">,</span> <span class="n">Put</span><span class="o">&gt;</span> <span class="p">{</span>

  <span class="nd">@Override</span>
  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">reduce</span><span class="p">(</span><span class="n">Text</span> <span class="n">key</span><span class="p">,</span> <span class="n">Iterable</span><span class="o">&lt;</span><span class="n">IntWritable</span><span class="o">&gt;</span> <span class="n">values</span><span class="p">,</span> <span class="n">Context</span> <span class="n">context</span><span class="p">)</span>
    <span class="kd">throws</span> <span class="n">IOException</span><span class="p">,</span> <span class="n">InterruptedException</span> <span class="p">{</span>
    <span class="kt">long</span> <span class="n">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="n">L</span><span class="p">;</span>
    <span class="k">for</span> <span class="p">(</span><span class="n">IntWritable</span> <span class="n">value</span> <span class="p">:</span> <span class="n">values</span><span class="p">)</span> <span class="p">{</span>
      <span class="n">sum</span> <span class="o">+=</span> <span class="n">value</span><span class="p">.</span><span class="na">get</span><span class="p">();</span>
    <span class="p">}</span>
    <span class="kt">byte</span><span class="o">[]</span> <span class="n">row</span> <span class="o">=</span> <span class="n">Bytes</span><span class="p">.</span><span class="na">toBytes</span><span class="p">(</span><span class="n">key</span><span class="p">.</span><span class="na">toString</span><span class="p">());</span>
    <span class="n">context</span><span class="p">.</span><span class="na">write</span><span class="p">(</span><span class="n">row</span><span class="p">,</span> <span class="k">new</span> <span class="n">Put</span><span class="p">(</span><span class="n">row</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;count&quot;</span><span class="p">,</span> <span class="n">sum</span><span class="p">));</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Note that here, the key is always ignored, because the <code class="docutils literal notranslate"><span class="pre">Put</span></code> that is provided as the value also
contains the row key. It would therefore also be safe to write null for the key:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="n">context</span><span class="p">.</span><span class="na">write</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="k">new</span> <span class="n">Put</span><span class="p">(</span><span class="n">row</span><span class="p">).</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;count&quot;</span><span class="p">,</span> <span class="n">sum</span><span class="p">));</span>
</pre></div>
</div>
</div>
<div class="section" id="pre-splitting-a-table-into-multiple-regions">
<span id="table-datasets-pre-splitting"></span><h2>Pre-Splitting a Table into Multiple Regions<a class="headerlink" href="#pre-splitting-a-table-into-multiple-regions" title="Permalink to this headline">🔗</a></h2>
<p>When the underlying storage for a Table Dataset (or any Dataset that uses a Table
underneath, such as a <code class="docutils literal notranslate"><span class="pre">KeyValueTable</span></code>) is HBase, CDAP allows you to
<a class="reference external" href="http://hbase.apache.org/book.html#manual_region_splitting_decisions">configure pre-splitting</a>
to gain a better distribution of data operations after the tables are created. This helps
optimize for better performance, depending on your use case.</p>
<p>To specify the splits for a Table-based Dataset, you use the <code class="docutils literal notranslate"><span class="pre">hbase.splits</span></code> dataset property.
The value must contain a JSON-formatted <code class="docutils literal notranslate"><span class="pre">byte[][]</span></code> of the split keys, such as:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="p">{</span> <span class="s">&quot;hbase.splits&quot;</span><span class="p">:</span> <span class="s">&quot;[[64],[128],[192]]&quot;</span> <span class="p">}</span>
</pre></div>
</div>
<p>The above will create four regions; the first of which will receive all rows whose first
byte is in the range 0…63; the second will receive the range 64…127, the third will
receive the range 128…191 and the fourth will receive the range 192…255.</p>
<p>You set Dataset properties when you create the Dataset, either during application
deployment or via CDAP’s HTTP RESTful APIs. The following is an example of the former; for
an example of the latter, please refer to the
<span class="xref std std-ref">Dataset section</span> of the <span class="xref std std-ref">RESTful API
:Reference</span>.</p>
<p>To configure pre-splitting for a Table created during application deployment, in your
application class’ <code class="docutils literal notranslate"><span class="pre">configure()</span></code> you specify:</p>
<div class="highlight-java notranslate"><div class="highlight"><pre><span></span><span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyApp</span> <span class="kd">extends</span> <span class="n">AbstractApplication</span> <span class="p">{</span>

  <span class="nd">@Override</span>
  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">configure</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">DatasetProperties</span> <span class="n">props</span> <span class="o">=</span>
        <span class="n">DatasetProperties</span><span class="p">.</span><span class="na">builder</span><span class="p">().</span><span class="na">add</span><span class="p">(</span><span class="s">&quot;hbase.splits&quot;</span><span class="p">,</span> <span class="s">&quot;[[64],[128],[192]]&quot;</span><span class="p">).</span><span class="na">build</span><span class="p">();</span>
    <span class="n">createDataset</span><span class="p">(</span><span class="s">&quot;myTable&quot;</span><span class="p">,</span> <span class="n">KeyValueTable</span><span class="p">.</span><span class="na">class</span><span class="p">,</span> <span class="n">props</span><span class="p">);</span>

    <span class="c1">// init other components</span>

  <span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>

</div>
    <div class="col-md-2">
      <div id="right-sidebar" class="bs-sidenav scrollable-y" role="complementary">
        <div id="localtoc-scrollspy">
        </div>
      </div>
    </div></div>
</div>
<!-- block main content end -->
<!-- block footer -->
<footer class="footer">
      <div class="container">
        <div class="row">
          <div class="col-md-2 footer-left"><a title="Datasets Overview" href="overview.html" />Previous</a></div>
          <div class="col-md-8 footer-center"><a class="footer-tab-link" href="../../table-of-contents/../../reference-manual/licenses/index.html">Copyright</a> &copy; 2014-2020 Cask Data, Inc.&bull; <a class="footer-tab-link" href="//docs.cask.co/cdap/6.1.1/cdap-docs-6.1.1-web.zip" rel="nofollow">Download</a> an archive or
<a class="footer-tab-link" href="//docs.cask.co/cdap">switch the version</a> of the documentation
          </div>
          <div class="col-md-2 footer-right"><a title="FileSet Dataset" href="fileset.html" />Next</a></div>
        </div>
      </div>
    </footer>
<!-- block footer end -->
<script type="text/javascript" src="../../_static/bootstrap-3.3.6/js/bootstrap.min.js"></script><script type="text/javascript" src="../../_static/js/bootstrap-sphinx.js"></script><script type="text/javascript" src="../../_static/js/abixTreeList-2.js"></script><script type="text/javascript" src="../../_static/js/cdap-dynamicscrollspy-4.js"></script><script type="text/javascript" src="../../_static/js/cdap-version-menu.js"></script><script type="text/javascript" src="../../_static/js/copy-to-clipboard.js"></script><script type="text/javascript" src="../../_static/js/jquery.mousewheel.min.js"></script><script type="text/javascript" src="../../_static/js/jquery.mCustomScrollbar.js"></script><script type="text/javascript" src="../../_static/js/js.cookie.js"></script><script type="text/javascript" src="../../_static/js/tabbed-parsed-literal-0.2.js"></script><script type="text/javascript" src="../../_static/js/cdap-onload-javascript.js"></script><script type="text/javascript" src="../../_static/js/cdap-version-menu.js"></script>
    <script src="https://cdap.gitee.io/docs/cdap/json-versions.js"/></script>
  </body>
</html>